import request from '../utils/request'

// 认证相关API
export const authApi = {
  // 用户登录
  login: (data: { username: string; password: string }) => {
    return request.post('/api/v1/auth/login', data)
  },
  
  // 用户注册
  register: (data: { username: string; email: string; password: string }) => {
    return request.post('/api/v1/auth/register', data)
  },
  
  // 获取当前用户信息
  getCurrentUser: () => {
    return request.get('/api/v1/auth/me')
  },
  
  // 刷新token
  refreshToken: () => {
    return request.post('/api/v1/auth/refresh')
  }
}

// 角色相关API
export const characterApi = {
  // 获取角色列表
  getCharacters: (params?: any) => {
    return request.get('/api/v1/characters', { params })
  },
  
  // 创建角色
  createCharacter: (data: any) => {
    return request.post('/api/v1/characters', data)
  }
}

// 聊天相关API
export const chatApi = {
  // 发送消息并获取AI回复
  sendMessage: (data: {
    character_id: number
    character_name: string
    novel_project: string
    novel_title: string
    message: string
    session_id?: number
  }) => {
    return request.post('/api/v1/chat/send', data)
  },
  
  getChatHistory: (session_id: number, params?: { limit?: number; offset?: number }) => {
    return request.get(`/api/v1/chat/history/${session_id}`, { params })
  },
  
  getActiveSessions: () => {
    return request.get('/api/v1/chat/sessions')
  },
  
  deleteSession: (session_id: number) => {
    return request.delete(`/api/v1/chat/sessions/${session_id}`)
  },
  
  textToSpeech: (data: { text: string; voice_type?: string }) => {
    return request.post('/api/v1/chat/tts', data)
  }
}

export const uploadApi = {
  uploadAvatar: (file: File) => {
    const formData = new FormData()
    formData.append('file', file)
    return request.post('/api/v1/files/upload/avatar', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  
  uploadAudio: (file: File) => {
    const formData = new FormData()
    formData.append('file', file)
    return request.post('/api/v1/files/upload/audio', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
}

export default {
  authApi,
  characterApi,
  chatApi,
  uploadApi
} 